package card;
import java.util.ArrayList;
import java.util.Random;

public class Game {
    //1：生成一副牌
    public ArrayList<Card> create() {
        ArrayList<Card> deck = new ArrayList<>();
        String[] suits = {"♣","♦","♥","♠"};
        for(int i = 0; i < 4; i++) {
            for(int j = 1; j <= 13; j++) {
                Card card = new Card(suits[i],j);
                deck.add(card);
            }
        }
        return deck;
    }
    //洗牌
    public void shuffle(ArrayList<Card> deck) {

        for(int i = 51; i >0; i--) {
            Random random = new Random();
            int x = random.nextInt(i);

            Card tmp = deck.get(i);
            deck.set(i,deck.get(x));
            deck.set(x,tmp);
        }
    }
    //抓牌
    public ArrayList<ArrayList<Card>> deal(ArrayList<Card> deck) {
        //给三个人发牌
        ArrayList<ArrayList<Card>> players = new ArrayList<>();
        ArrayList<Card> player1 = new ArrayList<>();
        ArrayList<Card> player2 = new ArrayList<>();
        ArrayList<Card> player3 = new ArrayList<>();
        players.add(player1);
        players.add(player2);
        players.add(player3);

        for(int i = 0; i < 5; i++) {
            for(int j = 0; j < 3; j++) {
                players.get(j).add(deck.remove(0));
            }
        }
        return players;
    }
}

